<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" id="file" onchange="upload()">
</body>
<script th:src="@{/js/jquery.js}"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    var base = /*[[@{/}]]*/ ''; //获取context-path
    /*]]>*/
</script>

<script type="text/javascript">
    function upload() {
        var file = document.getElementById("file").files[0];
        var fd = new FormData();
        fd.append("file", file);
        $.ajax({
            url: base + 'goods/upload',
            dataType: 'json',
            type: 'POST',
            async: true,
            data: fd,
            processDate: false,
            contentType: false,
            success: function (result) {
                alert("上传成功");
            }
        });
    }

</script>
</html>